package com.jxsd.edu.cn.struts2.daoImpl;

import com.jxsd.edu.cn.struts2.dao.AuthDao;
import com.jxsd.edu.cn.struts2.models.Auth;
import com.jxsd.edu.cn.tools.ResultBean;
import com.jxsd.edu.cn.tools.Template;

public class AuthDaoImpl  implements  AuthDao 
{

	@Override
	public Auth getAuth(String nickName) {
		String  sql="select   id,authCode,email,nickName,regisTime,aupwd  " +
				         "    from  auth  where  nickName=?";
		Object[]  params={nickName};
		Auth  auth=null;
		ResultBean<Auth>  bean=new  ResultBean<Auth>();
		try {
			auth=bean.handler(sql, params, Auth.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return   auth;
	}

	@Override
	public void deleteAuth(String nickName) {
		Object[]  params={nickName};
	    Template  template=new  Template();
	    String  sql="delete  from  auth  where  nickName=?";
	    template.update(sql, params);
	}

	@Override
	public void addAuth(Auth  auth) {
	    String  sql="insert   into  auth(authCode,email,nickName," +
	    		"regisTime,aupwd)  values(?,?,?,?,?)";
	    Object[]  params={auth.getAuthCode(),auth.getEmail(),
	    		auth.getNickName(),auth.getRegisTime(),auth.getAupwd()};
	    Template  template=new  Template();
	    template.update(sql, params);
	}

	@Override
	public boolean getEmail(String email) {
		String  sql="select  email  from  Auth  where  email=?";
		Object[]  params={email};
		ResultBean<Auth>  hander=new  ResultBean<Auth>();
		Auth  auth=null;
		try {
			auth=hander.handler(sql, params, Auth.class);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(auth.getNickName()!=null)
		{
			return  true;
		}
		return false;
	}

	@Override
	public void activeUser(Auth auth) {
		String sql="call   prc_activeUser(?,?)";
		Object[]  params={auth.getNickName(),auth.getAuthCode()};
		Template  t=new Template();
		t.callUpdate(sql, params);
	}
	
}
